package tech.ideashare.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import tech.ideashare.utils.IS_HttpUtils;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.util.Map;
import java.util.concurrent.TimeUnit;

import static tech.ideashare.base.APPCONST.*;
import static tech.ideashare.utils.SignUtils.sign;

@Controller
public class HomeController extends BaseController {



    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    @Autowired
    private RedisTemplate redisTemplate;


    @GetMapping("/")
    public String showHome(   HttpServletResponse response){
        logger.info("come in home");
        System.out.println(stringRedisTemplate.opsForValue().get("aaa"));
        System.out.println(stringRedisTemplate.opsForValue().get("bbb"));

        stringRedisTemplate.opsForValue().set("aaa", "111");
        stringRedisTemplate.opsForValue().set("bbb","222",3, TimeUnit.SECONDS);
        System.out.println(stringRedisTemplate.opsForValue().get("aaa"));
        System.out.println(stringRedisTemplate.opsForValue().get("bbb"));

        Cookie cookie = new Cookie("openid","asdfasdf");
        cookie.setMaxAge(72000);
        response.addCookie(cookie);

        return "index";
    }

    @GetMapping("/testwx")
    public String testwx( HttpServletResponse response  ) throws IOException {
        logger.info("come in testwx");

        response.sendRedirect("/wx/getAccessCode");
        return null;

    }






}
